﻿package mortal.game.view.guild.otherpanel
{
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.cache.guild.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuildDonateResource extends GuildOtherBasePanel
    {
        private var _numStepper:GNumericStepper;
        private var _btnDonate:GButton;
        private var _contributeTxt:GTextFiled;
        private var _baseItem:BaseItem;
        private var dataArr:Array;
        private var curData:ItemData;
        private var _uiCreateCom:Boolean = false;
        private var _donateNum:int;
        private static var _instance:GuildDonateResource;
        public static var item:ItemData;

        public function GuildDonateResource(param1:ILayer = null)
        {
            setSize(310, 170);
            super(param1);
            title = "" + Language.getString(71167);
            return;
        }// end function

        override public function layoutUI() : void
        {
            super.layoutUI();
            UIFactory.textField("" + Language.getString(71168), 20, 40, 274, 55, this);
            this._contributeTxt = UIFactory.textField("", 20, 125, 274, 22, this, GlobalStyle.textFormatBai);
            this._baseItem = UIFactory.baseItem(70, 70, 42, 42, this);
            this._baseItem.setItemStyle();
            this._numStepper = UIFactory.gNumericStepper(125, 80, 49, 20, this, 999, 1, "NumericStepper");
            this._numStepper.minimum = 1;
            this._numStepper.value = this._numStepper.minimum;
            this._numStepper.configEventListener(Event.CHANGE, this.onNumChange);
            this._btnDonate = UIFactory.gButton("" + Language.getString(71169), 205, 80, 49, 22, this);
            this.dataArr = this.getDataArr();
            if (this.dataArr.length == 0)
            {
                this.curData = new ItemData(180080000);
                this._baseItem.filters = [FilterConst.colorFilter2];
            }
            else
            {
                this.curData = this.dataArr[0];
                this._baseItem.filters = null;
            }
            if (this.curData == null)
            {
                return;
            }
            this._baseItem.itemData = this.curData;
            this._numStepper.maximum = this.curData.itemAmount;
            this.onNumChange();
            this._numStepper.value = Math.max(this.curData.itemAmount, this._donateNum);
            this._numStepper.maximum = Math.max(this.curData.itemAmount, this._donateNum);
            this._uiCreateCom = true;
            return;
        }// end function

        private function getDataArr() : Array
        {
            var _loc_1:Array = null;
            if (item == null)
            {
                _loc_1 = Cache.instance.pack.backPackCache.getPropByType(GuildConst.donateResourceCategory, GuildConst.donateResourceType);
            }
            else
            {
                _loc_1 = [item];
            }
            return _loc_1;
        }// end function

        private function onNumChange(event:Event = null) : void
        {
            this._contributeTxt.htmlText = Language.getStringByParam(60093, this._numStepper.value * 10, this._numStepper.value * 10);
            return;
        }// end function

        override public function onMouseClick(event:MouseEvent) : void
        {
            var _loc_2:SelfGuildInfo = null;
            var _loc_3:Object = null;
            var _loc_4:SPlayerItem = null;
            super.onMouseClick(event);
            if (this.curData == null)
            {
                return;
            }
            switch(event.target)
            {
                case this._btnDonate:
                {
                    if (this.curData.itemAmount < this._numStepper.value)
                    {
                        MsgManager.showRollTipsMsg("" + Language.getString(71170));
                        return;
                    }
                    _loc_2 = Cache.instance.guild.selfGuildInfo;
                    if (_loc_2.baseInfo.resource >= _loc_2.getLevelConfig().maxResource)
                    {
                        MsgManager.showRollTipsMsg("" + Language.getString(71171));
                        return;
                    }
                    _loc_3 = {};
                    _loc_4 = new SPlayerItem();
                    _loc_4.uid = this.curData.serverData.uid;
                    _loc_4.itemCode = this.curData.serverData.itemCode;
                    _loc_4.itemAmount = this._numStepper.value;
                    _loc_3.item = _loc_4;
                    _loc_3.money = new Dictionary();
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildDonateResource, _loc_3));
                    this.hide();
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            return;
        }// end function

        override public function update() : void
        {
            var _loc_1:Array = null;
            var _loc_2:ItemData = null;
            super.update();
            _loc_1 = this.getDataArr();
            if (_loc_1.length == 0)
            {
                _loc_2 = new ItemData(180080000);
            }
            else
            {
                _loc_2 = _loc_1[0];
            }
            this._numStepper.value = Math.max(_loc_2.itemAmount, this._donateNum);
            this._numStepper.maximum = Math.max(_loc_2.itemAmount, this._donateNum);
            return;
        }// end function

        override public function hide() : void
        {
            this.dataArr = null;
            this.curData = null;
            super.hide();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            paddingBottom = 10;
            this._donateNum = 0;
            this._numStepper = null;
            this._btnDonate = null;
            this._contributeTxt = null;
            this._baseItem = null;
            item = null;
            return;
        }// end function

        override protected function configParams() : void
        {
            super.configParams();
            paddingBottom = 10;
            return;
        }// end function

        public function set donateNum(param1:int) : void
        {
            this._donateNum = param1;
            return;
        }// end function

        public static function get instance() : GuildDonateResource
        {
            if (_instance == null)
            {
                _instance = new GuildDonateResource;
            }
            return _instance;
        }// end function

    }
}
